package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.entity.SysBuild;
import com.gec.model.entity.SysCommunity;
import com.gec.model.vo.SysBuildQueryVo;
import com.gec.model.vo.SysCommunityQueryVo;
import com.gec.system.service.SysBuildService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 楼栋表 前端控制器
 * </p>
 *
 * @author Liangxj
 * @since 2023-12-06
 */
@Api(tags = "楼栋管理控制器")
@RestController
@RequestMapping("/admin/system/sysBuild")
public class SysBuildController {

    @Autowired
    private SysBuildService sysBuildService;

    // 分页和条件查询
    @ApiOperation("分页和条件查询")
    @GetMapping("/{page}/{limit}")
    public Result selectBuildPageVo(@PathVariable Long page,
                                        @PathVariable Long limit,
                                        SysBuildQueryVo sysBuildQueryVo
    ){
        IPage<SysBuild> iPage =new Page<>(page,limit);

        System.out.println("iPage条件："+iPage);

        iPage=this.sysBuildService.selectPage(iPage,sysBuildQueryVo);

        System.out.println("控制层打印楼栋信息："+iPage);
        return Result.ok(iPage);
    }

    //添加楼栋
    @ApiOperation("添加楼栋")
    @PostMapping("/addBuild")
    public Result addBuild(@RequestBody SysBuild SysBuild){

        boolean save = this.sysBuildService.save(SysBuild);
        return save ? Result.ok() : Result.fail();
    }
    //删除单个楼栋
    @ApiOperation("删除楼栋")
    @GetMapping("/removeBuildById/{id}")
    public Result removeBuildById(@PathVariable Long id){
        boolean b = this.sysBuildService.removeById(id);
        return b ? Result.ok():Result.fail();
    }

    //删除多个楼栋
    @ApiOperation("删除多个楼栋")
    @DeleteMapping("/removeBuildByIds")
    public Result removeBuildByIds(@RequestBody List<Long> ids){
        boolean b = this.sysBuildService.removeByIds(ids);
        return b ? Result.ok():Result.fail();
    }

    //根据id查询当前要修改的楼栋
    @ApiOperation("根据id查询当前要修改的楼栋")
    @GetMapping("/finBuildById/{id}")
    public Result finBuildById(@PathVariable Long id){
        SysBuild byId = this.sysBuildService.getById(id);
        return Result.ok(byId);
    }
    //修改
    @ApiOperation("根据id修改当前楼栋")
    @PostMapping("/updateBuild")
    public Result updateBuild(@RequestBody SysBuild sysBuild){
        boolean b = this.sysBuildService.updateById(sysBuild);
        return b ? Result.ok():Result.fail();
    }

    @ApiOperation("查询所有楼栋")
    @GetMapping("/finAllBuild")
    public Result finAllBuild(){
        List<SysBuild> list = this.sysBuildService.list();
        return Result.ok(list);
    }

}

